document.onkeydown = function getKeyCode(event) {
    event = event || window.event;
    switch (event.keyCode) {
        case 8:
            event.preventDefault();
            fun_back();
            break;
        case 640:
            event.preventDefault();
            fun_back();
            break;
        case 13: //确定
            fun_enter();
            break;
        case 37: //左
            fun_left();
            break;
        case 39: //右
            fun_right();
            break;
    }
    if(event.keyCode!=8 && event.keyCode!=640 && event.keyCode!=13){
        setCookie("currContent", currContent);
        setCookie("currPage", currPage);
    }

};

function fun_back(){
    var back_url = GetQueryString("back_url");
    if(back_url!=null && back_url!=''){
        document.getElementsByTagName("body")[0].innerHTML = '';
        delCookie("currPage");
        delCookie("currContent");
        window.location.href =decodeURIComponent(back_url);
    }
}


function fun_enter() {
    var num = parseInt(currContent)+parseInt(currPage)-1;
    //判断是理财还是保险  理财1 保险2
    var local = window.location.href;
    window.location = "list.html?id="+navJson[num-1].id+"&name="+navJson[num-1].title+"&back_url="+encodeURIComponent(local);
}


function fun_right(){
    var totalC = document.getElementById("content").children.length;
    if (totalC>5 && currContent == totalC-1) {//翻页
        currPage++;
        currContent = 5;
        setCookie("currContent", currContent);
        setCookie("currPage", currPage);
        showProductType();
    } else if ((currContent < totalC) && totalC<6) {
        currContent++;
        setCookie("currContent", currContent);
        addBorder(currContent);
    }
}

function fun_left(){
    if (currPage > 1) {
        currPage--;
        currContent = 5;
        setCookie("currPage", currPage);
        setCookie("currContent", currContent);
        showProductType();
    }else if (currPage == 1) {
        //是否有上一页
        if (currContent > 1) {
            currContent--;
            addBorder(currContent)
        }
    }
}
